package com.etc.controller;

import com.etc.entity.RoomInfo;
import com.etc.service.RoomInfoService;
import com.etc.util.Layui;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/RoomInfosController")
public class RoomInfosController {

    @Autowired
    RoomInfoService service;

    /**
     * 增加房间
     * 邓玲琪
     * @param
     * @return boolean int>0 为True  否则为False
     */
    @RequestMapping("/addRoomInfo")
    @ResponseBody
    public int addRoomInfo(@RequestParam(value = "roomNum")int roomNum,
                           @RequestParam(value = "rtId")String rtId,
                           @RequestParam(value = "roomTel")String roomTel,
                           @RequestParam(value = "roomFloog")String roomFloog,
                           @RequestParam(value = "roomStatus")int roomStatus){
        //调用业务层
        int fian = service.addRoomInfo(roomNum,rtId,roomTel,roomStatus,roomFloog);
        return fian;
    }

    /**
     * 根据房间编号删除房间
     * 邓玲琪
     * @param roomId 房间编号
     * @return boolean int>0 为True  否则为False
     */
    @RequestMapping("/delRoomInfo")
    @ResponseBody
    public int delRoomInfo(@RequestParam(value = "roomId")String roomId){
        //调用业务层
        int fian = service.delRoomInfo(roomId);
        return fian;
    }
    /**
     * 根据房间编号修改房间信息
     * 邓玲琪
     * @param
     * @return boolean int>0 为True  否则为False
     */
    @RequestMapping("/modifyRoomInfo")
    @ResponseBody
    public int modifyRoomInfo(@RequestParam(value = "roomId")String roomId,
                              @RequestParam(value = "roomTel")String roomTel,
                              @RequestParam(value = "roomStatus")int roomStatus){
        RoomInfo roomInfo=new RoomInfo(roomId,roomStatus,roomTel);
        //调用业务层
        int fian = service.modifyRoomInfo(roomInfo);
        return fian;
    }
    /**
     * 分页 查找所有房间信息
     * 邓玲琪
     *  @param pageNum
     * @param pageSize
     * @return pageInfo  （集合PageInfo<RoomInfo>）
     */
    @RequestMapping("/getqueryAllRoomInfo")
    @ResponseBody
    public Layui getqueryAllRoomInfo(@RequestParam(value = "pageNum",defaultValue = "1")int pageNum,
                                     @RequestParam(value = "pageSize",defaultValue = "3")int pageSize,
                                     @RequestParam(value = "roomNum",defaultValue = "0")int roomNum,
                                     @RequestParam(value = "roomStatus",defaultValue = "88")int roomStatus,
                                     @RequestParam(value = "rtName",defaultValue = "")String rtName){
        PageInfo<RoomInfo> pageInfo=service.getqueryAllRoomInfo(pageNum,pageSize,roomNum,roomStatus,rtName);
        return Layui.data(pageInfo.getTotal(),pageInfo.getList());
    }
}
